//
//  DeleteAccountView.swift
//  ezyform
//
//  Created by Moennig Q on 7/2/2022.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit

class DeleteAccountView: MeModelVCBaseView {
    var delAccountBtn: OperationButton!
    var delAccountClosure : (()->Void)?
    let circleViewSize: CGSize = CGSize(width: 8, height: 8)
    
    let checkBoxBtn = CheckboxButton(title: R.string.localizable.meDeleteAccountTipAgree())
    override func setUpviews() {
        //
        let contentBackView = UIView()
        contentBackView.backgroundColor = .white
        self.addSubview(contentBackView)
        contentBackView.snp.makeConstraints { make in
            make.top.equalTo(self.topBackView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        //bottom View（勾选框和delete account按钮在一起）
        let bottomView = View()
        contentBackView.addSubview(bottomView)
        bottomView.snp.makeConstraints { (make) in
            make.bottom.equalTo(OperationButton.bottomMargin)
            make.left.right.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
        }
        delAccountBtn = OperationButton(R.string.localizable.deleteAccount(),enabled: false)
        bottomView.addSubview(delAccountBtn)
        delAccountBtn.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.height.equalTo(OperationButton.height)
        }
        bottomView.addSubview(checkBoxBtn)
        checkBoxBtn.snp.makeConstraints { make in
            make.bottom.equalTo(delAccountBtn.snp.top).offset(-5)
            make.left.right.equalTo(delAccountBtn)
            make.height.greaterThanOrEqualTo(0)
            make.top.equalTo(5)
        }
        //
        let scrollView = DIYScrollView()
        scrollView.backgroundColor = .white
        contentBackView.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.right.equalTo(self)
            make.bottom.equalTo(bottomView.snp.top)
        }
        
        let contentView = UIView()
        contentView.backgroundColor = .clear
        scrollView.addSubview(contentView)
        
        contentView.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(scrollView)
            make.left.right.equalTo(self)
            make.height.greaterThanOrEqualTo(0)
        }
        //title
        let titleLabel = BaseLabel()
        titleLabel.text = R.string.localizable.meDeleteAccountTipTitle(APPConfig.loginInfo.email)
        titleLabel.setFont(R.font.interMedium(size: 14))
        titleLabel.textColor = UIColor(hexStr: "#292D3299")
        titleLabel.textAlignment = .left
        titleLabel.lineBreakMode = .byWordWrapping
        titleLabel.numberOfLines = 0
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.height.greaterThanOrEqualTo(0)
        }
        let termsBackView = UIView()
        termsBackView.backgroundColor = UIColor(hexStr: "#F5F5F5")
        termsBackView.layer.cornerRadius = Constant.StandardCornerRadius
        termsBackView.clipsToBounds = true
        contentView.addSubview(termsBackView)
        termsBackView.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(12)
            make.right.left.equalTo(titleLabel)
            make.height.greaterThanOrEqualTo(0)
            make.bottom.equalTo(-20)
        }
        
        //tip 1 circle view
        let circleView1 = self.generateCircleView()
        termsBackView.addSubview(circleView1)
        circleView1.snp.makeConstraints { make in
            make.top.equalTo(18)
            make.left.equalTo(12)
            make.size.equalTo(circleViewSize)
        }
        //tip 1 label
        let tip1Label = self.generateTermsLabel(R.string.localizable.meDeleteAccountTipContentOne())
        termsBackView.addSubview(tip1Label)
        tip1Label.snp.makeConstraints { make in
            make.top.equalTo(circleView1).offset(-5)
            make.left.equalTo(circleView1.snp.right).offset(12)
            make.right.equalTo(-12)
            make.height.greaterThanOrEqualTo(circleViewSize.height)
        }
        //tip 2 circle view
        let circleView2 = self.generateCircleView()
        termsBackView.addSubview(circleView2)
        circleView2.snp.makeConstraints { make in
            make.top.equalTo(tip1Label.snp.bottom).offset(18)
            make.left.equalTo(circleView1)
            make.size.equalTo(circleViewSize)
        }
        //tip 2 label
        let tip2Label = self.generateTermsLabel(R.string.localizable.meDeleteAccountTipContentTwo())
        termsBackView.addSubview(tip2Label)
        tip2Label.snp.makeConstraints { make in
            make.top.equalTo(circleView2).offset(-5)
            make.left.equalTo(tip1Label)
            make.right.equalTo(tip1Label)
            make.height.greaterThanOrEqualTo(circleViewSize.height)
        }
        //tip 3 circle view
        let circleView3 = self.generateCircleView()
        termsBackView.addSubview(circleView3)
        circleView3.snp.makeConstraints { make in
            make.top.equalTo(tip2Label.snp.bottom).offset(18)
            make.left.equalTo(circleView1)
            make.size.equalTo(circleViewSize)
        }
        //tip 3 label
        let tip3Label = self.generateTermsLabel(R.string.localizable.meDeleteAccountTipContentThree())
        termsBackView.addSubview(tip3Label)
        tip3Label.snp.makeConstraints { make in
            make.top.equalTo(circleView3).offset(-5)
            make.left.equalTo(tip1Label)
            make.right.equalTo(tip1Label)
            make.height.greaterThanOrEqualTo(circleViewSize.height)
        }
        //tip 4 circle view
        let circleView4 = self.generateCircleView()
        termsBackView.addSubview(circleView4)
        circleView4.snp.makeConstraints { make in
            make.top.equalTo(tip3Label.snp.bottom).offset(15)
            make.left.equalTo(circleView1)
            make.size.equalTo(circleViewSize)
        }
        //tip 4 label
        let tip4Label = self.generateTermsLabel(R.string.localizable.meDeleteAccountTipContentFour())
        termsBackView.addSubview(tip4Label)
        tip4Label.snp.makeConstraints { make in
            make.top.equalTo(circleView4).offset(-5)
            make.left.equalTo(tip1Label)
            make.right.equalTo(tip1Label)
            make.height.greaterThanOrEqualTo(circleViewSize.height)
        }
        //tip 5 circle view
        let circleView5 = self.generateCircleView()
        termsBackView.addSubview(circleView5)
        circleView5.snp.makeConstraints { make in
            make.top.equalTo(tip4Label.snp.bottom).offset(15)
            make.left.equalTo(circleView1)
            make.size.equalTo(circleViewSize)
        }
        //tip 5 label
        let tip5Label = self.generateTermsLabel(R.string.localizable.meDeleteAccountTipContentFive())
        termsBackView.addSubview(tip5Label)
        tip5Label.snp.makeConstraints { make in
            make.top.equalTo(circleView5).offset(-5)
            make.left.equalTo(tip1Label)
            make.right.equalTo(tip1Label)
            make.height.greaterThanOrEqualTo(circleViewSize.height)
            make.bottom.equalTo(-12)
        }
        
        //MARK: - 勾选同意删除协议
        checkBoxBtn.clickClosure = { tag in
            if tag == 1{
                self.delAccountBtn.enableBtn()
            }else{
                self.delAccountBtn.disableBtn()
            }
        }
        delAccountBtn.addTarget(self, action: #selector(delAccountBtnClick), for: UIControl.Event.touchUpInside)
    }
    @objc func delAccountBtnClick(){
        self.delAccountClosure?()
    }
    private func generateCircleView()->UIView{
        let view = UIView()
        view.backgroundColor = UIColor(hexStr: "#379657")
        view.layer.cornerRadius = self.circleViewSize.height / 2
        view.clipsToBounds = true
        return view
    }
    private func generateTermsLabel(_ content: String)->BaseLabel{
        let view = BaseLabel()
        view.text = content
        view.setFont(R.font.interMedium(size: 14))
        view.textColor = UIColor(hexStr: "#292D32")
        view.textAlignment = .left
        view.lineBreakMode = .byWordWrapping
        view.numberOfLines = 0
        return view
    }
}
